package com.csii.activiti.server.api;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.csii.activiti.server.api.vo.Result;
import com.csii.activiti.server.core.entity.ActFlowCommonParam;
import com.csii.activiti.server.core.entity.db.ActFlowCallbackEntity;
import com.csii.activiti.server.core.query.QueryFlowCallback;
import com.csii.activiti.server.core.service.FlowCallbackManagementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


@Api(tags="流程回调管理")
@RestController
@RequestMapping("/${activity.basic.url:activiti}/flow/callbackManagement")
@Slf4j
public class FlowCallbackManagementController {

    @Autowired
    private FlowCallbackManagementService flowCallbackManagementService;


    @ApiOperation("查询数据列表")
    @GetMapping("/queryData")
    public Result<Page<ActFlowCallbackEntity>> queryData(QueryFlowCallback queryFlowCallback, @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                                         @RequestParam(name="pageSize", defaultValue="10") Integer pageSize){
        return Result.ok(flowCallbackManagementService.queryData(queryFlowCallback,new Page(pageNo, pageSize)));
    }

    @ApiOperation("更新数据")
    @PostMapping("/updateData")
    public Result updateData(@RequestBody ActFlowCallbackEntity actFlowCallbackEntity){
        flowCallbackManagementService.updateFlowCallbackData(actFlowCallbackEntity);
        return Result.ok();
    }

    @ApiOperation("根据ID重新回调")
    @PostMapping("/reCallbackById")
    public Result reCallbackById(@RequestBody ActFlowCommonParam param){
        flowCallbackManagementService.reCallbackById(param.getId());
        return Result.ok();
    }
}
